package J4_28;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class test {
    public static void main1(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        while (n-- > 0) { // 注意 while 处理多个 case
            int a = in.nextInt();
            int b = in.nextInt();
            String str = in.next();
            int ret = getRet(a,b,str);
            System.out.println(ret);
        }
    }

    private static int getRet(int a, int b, String str) {
        int ret = 0;
        char[] ch = str.toCharArray();
        for (int i = 0; i < a; i++) {
            if (ch[i] == 'W') {
                ret++;
                if (i > 1 && ch[i-2] == 'W' && ch[i-1] == 'W') {
                    ret--;
                    ret+=b;
                }
            }else {
                ret--;
            }
        }
        return ret;
    }

    public static int maxLength (int[] arr) {
        if (arr.length==0)return 0;
        int ret = 1;
        HashMap<Integer, Integer> map = new HashMap<>();
        map.put(arr[0],0);
        for (int i = 0; i < arr.length; i++) {
            for (int j = i + 1; j < arr.length; j++) {
                if (map.containsKey(arr[j])) {
                    ret = Math.max(ret,j-i);
                    i = map.get(arr[j]+1);
                    map.put(arr[j],j);
                }
                if (j == arr.length-1) {
                    ret = Math.max(ret,j - i + 1);
                }
            }
        }
        return ret;
    }

    public static void main(String[] args) {
        int[] arr = new int[]{2,3,4,5};
        maxLength(arr);
    }
}
